Completed
Push — master ( 158ed8...34f194 )
by Alejandro
04:53 queued 02:19
created

ShortUrlsRow.js ➔ render   A

Complexity

Conditions 1

Size

Total Lines 31
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 31
ccs 3
cts 3
cp 1
rs 9.184
c 0
b 0
f 0
cc 1
crap 1
1
import { isEmpty } from 'ramda';
2
import React from 'react';
3
import Moment from 'react-moment';
4
import PropTypes from 'prop-types';
5
import { shortUrlsListParamsType } from '../reducers/shortUrlsListParams';
6
import { serverType } from '../../servers/prop-types';
7
import ExternalLink from '../../utils/ExternalLink';
8
import { shortUrlType } from '../reducers/shortUrlsList';
9
import Tag from '../../tags/helpers/Tag';
10
import './ShortUrlsRow.scss';
11
12 1
const ShortUrlsRow = (
13
  ShortUrlsRowMenu,
14
  colorGenerator,
15
  stateFlagTimeout
16 8
) => class ShortUrlsRow extends React.Component {
17
  static propTypes = {
18
    refreshList: PropTypes.func,
19
    shortUrlsListParams: shortUrlsListParamsType,
20
    selectedServer: serverType,
21
    shortUrl: shortUrlType,
22
  };
23
24
  state = { copiedToClipboard: false };
25
26
  renderTags(tags) {
27 10
    if (isEmpty(tags)) {
28 1
      return <i className="nowrap"><small>No tags</small></i>;
29
    }
30
31 9
    const { refreshList, shortUrlsListParams } = this.props;
32 9
    const selectedTags = shortUrlsListParams.tags || [];
33
34 9
    return tags.map((tag) => (
35 18
      <Tag
36
        colorGenerator={colorGenerator}
37
        key={tag}
38
        text={tag}
39
        onClick={() => refreshList({ tags: [ ...selectedTags, tag ] })}
40
      />
41
    ));
42
  }
43
44
  render() {
45 10
    const { shortUrl, selectedServer } = this.props;
46
47 10
    return (
48
      <tr className="short-urls-row">
49
        <td className="nowrap short-urls-row__cell" data-th="Created at: ">
50
          <Moment format="YYYY-MM-DD HH:mm">{shortUrl.dateCreated}</Moment>
51
        </td>
52
        <td className="short-urls-row__cell" data-th="Short URL: ">
53
          <ExternalLink href={shortUrl.shortUrl} />
54
        </td>
55
        <td className="short-urls-row__cell short-urls-row__cell--break" data-th="Long URL: ">
56
          <ExternalLink href={shortUrl.longUrl} />
57
        </td>
58
        <td className="short-urls-row__cell" data-th="Tags: ">{this.renderTags(shortUrl.tags)}</td>
59
        <td className="short-urls-row__cell text-md-right" data-th="Visits: ">{shortUrl.visitsCount}</td>
60
        <td className="short-urls-row__cell short-urls-row__cell--relative">
61
          <small
62
            className="badge badge-warning short-urls-row__copy-hint"
63
            hidden={!this.state.copiedToClipboard}
64
          >
65
            Copied short URL!
66
          </small>
67
          <ShortUrlsRowMenu
68
            selectedServer={selectedServer}
69
            shortUrl={shortUrl}
70 1
            onCopyToClipboard={() => stateFlagTimeout(this.setState.bind(this), 'copiedToClipboard')}
71
          />
72
        </td>
73
      </tr>
74
    );
75
  }
76
};
77
78
export default ShortUrlsRow;
79